package com.rzj.demo.demos.mapper;

import com.rzj.demo.demos.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
// import org.apache.ibatis.annotations.Param;

// 动态SQL练习
@Mapper
public interface UserInfoMapper2 {
    @Insert("<script>" +
            "insert into user_info (username,password,age," +
            "<if test = 'gender!=null'>gender,</if>" +
            "phone)" +
            "values(#{username},#{password},#{age}," +
            "<if test = 'gender!=null'>#{gender},</if>" +
            "#{phone})" +
            "</script>")
    Integer insert2(UserInfo userInfo);// 实现

    Integer insertByXML(UserInfo userInfo);

    List<UserInfo> selectByCondicition(UserInfo userInfo);

    // 注解的方式
    @Select("<script> " +
            " select * from user_info" +
            "        <where>" +
            "            <if test='username != null'>" +
            "                username = #{username}" +
            "            </if>" +
            "            <if test='age != null'>" +
            "                and age = #{age}" +
            "            </if>" +
            "            <if test='gender != null'>" +
            "                and gender = #{gender}" +
            "            </if>" +
            "        </where>" +
            "</script>")
    List<UserInfo> selectByCondicition2(UserInfo userInfo);

    // 使用trim标签
    Integer updateByCondicition3(UserInfo userInfo);

    // 使用set标签
    Integer updateByCondicition(UserInfo userInfo);

    // 批量delete
    Integer batchDelete(List<Integer> ids);
}
